package edu.hwadee.BEIS.util;

import java.util.HashSet;
import java.util.Set;

import com.alibaba.fastjson.JSON;

import edu.hwadee.BEIS.constants.ResultEnum;
import edu.hwadee.BEIS.entity.JsonResult;

/**
 * 结果工具类
 * 生成返回JsonResult结果类
 * @author kingsong
 *
 */
public class ResultUtil {

	public static JsonResult success(Object object) {
		JsonResult result = new JsonResult();
		result.setCode(ResultEnum.SUCCESS.getCode());
		result.setMsg(ResultEnum.SUCCESS.getMsg());
		result.setData(object);
		return result;
	}

	public static JsonResult success() {
		return success(null);
	}

	public static JsonResult error(Integer code, String msg) {
		JsonResult result = new JsonResult();
		result.setCode(code);
		result.setMsg(msg);
		return result;
	}
	
	public static JsonResult error(ResultEnum re) {
		JsonResult result = new JsonResult();
		result.setCode(re.getCode());
		result.setMsg(re.getMsg());
		return result;
	}
	
//	public static void main(String[] args) {
//		Set<String> number = new HashSet<String>();
//		number.add("DS101");
//		number.add("DS102");
//		System.out.println(JSON.toJSON(number));
//	}
}
